var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("PureHelper"),
    s = cc._decorator,
    l = s.ccclass,
    _ = s.property,
    c = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.touch_node = null),
                (t.touch_bg = null),
                (t.touch_bar = null),
                (t.my_hero_node = null),
                (t.my_hero_ske = null),
                (t.role_move = !1),
                (t.moveDir = new cc.Vec2(0, 0)),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this),
                    this.my_hero_ske.setAnimation(0, "battle_idle", !0),
                    this.emitEvent(n.default.SEND_PLAYER_POS_INFO, this.my_hero_node),
                    this.updateTime();
            }),
            (t.prototype.addEvent = function () {
                this.touch_node.on(cc.Node.EventType.TOUCH_START, this.TouchStart, this),
                    this.touch_node.on(cc.Node.EventType.TOUCH_MOVE, this.TouchMove, this),
                    this.touch_node.on(cc.Node.EventType.TOUCH_END, this.TouchEnd, this),
                    this.touch_node.on(cc.Node.EventType.TOUCH_CANCEL, this.TouchEnd, this);
            }),
            (t.prototype.TouchStart = function (e) {
                var t = e.touch.getLocation();
                (t = this.touch_node.convertToNodeSpaceAR(t)), this.touch_bg.setPosition(t);
            }),
            (t.prototype.TouchMove = function (e) {
                var t = e.touch.getLocation();
                (t = this.touch_bg.convertToNodeSpaceAR(t)),
                    Math.abs(r.default.Distance(t, cc.v2(0, 0))) > 100 &&
                    (t = r.default.getTailPosOuter(t, cc.v2(0, 0), -100)),
                    this.touch_bar.setPosition(t);
                var o = cc.v2(t.x, t.y).sub(cc.v2(0, 0)).normalize();
                this.myHeroMove(o);
            }),
            (t.prototype.TouchEnd = function () {
                this.touch_bar.setPosition(cc.v2(0, 0)),
                    this.myRoleStopMove(),
                    this.touch_bg.setPosition(cc.v2(-70, -15));
            }),
            (t.prototype.myHeroMove = function (e) {
                (this.moveDir = e),
                    this.role_move || ((this.role_move = !0), this.my_hero_ske.setAnimation(0, "run", !0));
            }),
            (t.prototype.myRoleStopMove = function () {
                (this.role_move = !1),
                    this.my_hero_ske.setAnimation(0, "battle_idle", !0),
                    this.my_hero_node.stopAllActions();
            }),
            (t.prototype.updateTime = function () {
                var e = this;
                this.role_move && this.roleMove(),
                    this.scheduleOnce(function () {
                        e.updateTime();
                    }, i.GlobalParams.GameUpdateTime);
            }),
            (t.prototype.roleMove = function () {
                0 != this.moveDir.x &&
                    (this.my_hero_ske.node.scaleX =
                        Math.abs(this.my_hero_ske.node.scaleX) * (this.moveDir.x < 0 ? 1 : -1));
                var e = this.my_hero_node.getPosition().add(this.moveDir.mul(40));
                (e.x = e.x < -1170 ? -1170 : e.x),
                    (e.x = e.x > 1170 ? 1170 : e.x),
                    (e.y = e.y > 130 ? 130 : e.y),
                    (e.y = e.y < -380 ? -380 : e.y),
                    cc
                        .tween(this.my_hero_node)
                        .to(i.GlobalParams.GameUpdateTime, { position: cc.v2(e.x, e.y) })
                        .start();
            }),
            oo([_(cc.Node)], t.prototype, "touch_node", void 0),
            oo([_(cc.Node)], t.prototype, "touch_bg", void 0),
            oo([_(cc.Node)], t.prototype, "touch_bar", void 0),
            oo([_(cc.Node)], t.prototype, "my_hero_node", void 0),
            oo([_(sp.Skeleton)], t.prototype, "my_hero_ske", void 0),
            oo([l], t)
        );
    })(a.default);
o.default = c;
